package com.migo.utils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * Created by Wes on 2018/11/27.
 */
public final class MD5 {
    public MD5() {
    }

    public static String encrypt(String password) {
        try {
            MessageDigest alg = MessageDigest.getInstance("MD5");
            alg.update(password.getBytes());
            byte[] digesta = alg.digest();
            return byte2hex(digesta);
        } catch (NoSuchAlgorithmException var3) {
            return null;
        }
    }

    private static String byte2hex(byte[] bstr) {
        StringBuffer hs = new StringBuffer();
        String stmp = "";

        for(int n = 0; n < bstr.length; ++n) {
            stmp = Integer.toHexString(bstr[n] & 255);
            if(stmp.length() == 1) {
                hs.append("0");
                hs.append(stmp);
            } else {
                hs.append(stmp);
            }
        }

        return hs.toString();
    }
}
